﻿<template>
   <div>
     <query-table ref="dict_query_table" :columns="dictColumns" :query-fields="dictQueryFields" :detail-fields="dictFields"
                  :append-buttons="dictAppendButtons" base-url="/dict" show-index></query-table>
     <div v-if="currentDict">
       <h2 >{{currentDict.name}}字典值</h2>
      <query-table :key="'dict-value-'+(currentDict?currentDict.id:'')" ref="dict_value_query_table" :columns="dictValueColumns" :query-fields="dictValueQueryFields"
                   :detail-fields="dictValueFields" :append-buttons="dictValueAppendButtons"
                   :default-query-params="{dictId:currentDict.id}"
                   base-url="/dict_value" show-index></query-table>
     </div>
  </div>
</template>

<script>
//校验规则
var validateRules={
  name: [{ required: true, message: "请输入名称", trigger: "blur" }],
      id: [{ required: true, message: "请输入编码", trigger: "blur" }],
};
export default {
  $$route:{
    meta:{
      title:'数据字典'
    }
  },
  name: "DictList",
  data() {
    return {
      //字典展示列信息
      dictColumns: [
        {id: 'name', name: '字典名称', width: 150},
        {id: 'id', name: '字典ID', width: 150},
        {id: 'type', name: '字典类型', type:'meta',source:'dict-type',width: 100},
        {id: 'state', name: '字典状态', type:'meta',source:'dict-state', width: 100},
        {id: 'sort', name: '排序值', width: 100},
        {id: 'createTime', name: '创建日期', width: 150},
        {
          id: 'operation', name: '操作', type: 'button', children: [
            {text: '编辑', permission: 'sys_dict:update', operation: 'edit'},
            {text: '字典值', click: this.loadDictValueList},
            {text: '删除', type: 'danger', permission: 'sys_dict:delete'
              , operation: 'delete',isDisabled:(data)=>{return data.type=='enum'}
            },
          ]
        },
      ],
      //查询条件区域附加按钮
      dictAppendButtons: [{text: '新增', type: 'success', operation: 'create'}],
      dictValueAppendButtons: [{text: '新增', type: 'success', operation: 'create'}],
      //查询条件字段
      dictQueryFields: [
        {id: 'name', name: '字典名称', colSpan: 6},
        {id: 'code', name: '字典类型', component:'meta-select', type:'dict-type', colSpan: 6},
        // {id: 'officeRelated', name: '单位相关', colSpan: 6, component: 'data-select',data:[{id:'true',name:'是'},{id:'false',name:'否'}]},
      ],
      dictFields: [{
        id: 'id',
        name: '字典ID',
        show: true,
        disableOnEdit: true, //编辑时禁用
        rules: validateRules.id,
      }, {
        id: 'name',
        name: '名称',
        rules:validateRules.name,
      },{
        id:'type',
        name:'类型',
        component: 'meta-select',
        type:'dict-type',
        defaultValue:'custom',
        isDisabled:()=>{return true}
      }, {
        id: 'sort',
        name: '排序值',
        component: 'input',
        colSpan: 12
      }, {
        id:'state',
        name:'状态',
        component: 'meta-select',
        type:'dict-state',
        defaultValue:'normal',
      }, {
        id: 'description',
        name: '描述',
        component: 'textarea',
        colSpan: 24
      }],

      //字典值展示列信息
      dictValueColumns: [
        {id: 'name', name: '字典值名称', width: 150},
        {id: 'code', name: '字典值编码', width: 150},
        {id: 'type', name: '字典值类型', type:'meta',source:'dict-type',width: 100},
        {id: 'state', name: '字典值状态', type:'meta',source:'dict-state', width: 100},
        {id: 'sort', name: '排序值', width: 100},
        {id: 'createTime', name: '创建日期', width: 150},
        {
          id: 'operation', name: '操作', type: 'button', children: [
            {text: '编辑', permission: 'sys_dict:update', operation: 'edit'},
            {text: '删除', type: 'danger', permission: 'sys_dict:delete', operation: 'delete',isDisabled:(data)=>{return data.type=='enum';}},
          ]
        },
      ],
      //查询条件字段
      dictValueQueryFields: [
        {id: 'name', name: '字典值名称', colSpan: 6},
        {id: 'code', name: '字典值类型', component:'meta-select', type:'dict-type', colSpan: 6},
      ],
      dictValueFields: [{
        id: 'dictId',
        name: '字典ID',
        hide:true,
        getDefaultValue:()=>{
          return this.currentDict.id;
        }
      },{
        id: 'code',
        name: '编码',
        show: true,
        disableOnEdit: true, //编辑时禁用
        rules:validateRules.id,
      }, {
        id: 'name',
        name: '名称',
        rules:validateRules.name,
      },{
        id:'type',
        name:'类型',
        component:'meta-select',
        type:'dict-type',
        defaultValue:'custom',
        isDisabled:()=>{return true}
      }, {
        id: 'sort',
        name: '排序值',
        component: 'input',
        colSpan: 12
      }, {
        id:'state',
        name:'状态',
        component: 'meta-select',
        type:'dict-state',
        defaultValue:'normal',
      }, {
        id: 'description',
        name: '描述',
        component: 'textarea',
        colSpan: 24
      }],

      checkList:[],
      queryCondition: {},
      isDictLoading: false,
      isDictValueLoading: false,
      formLabelWidth: "120px",
      dictValueList: [],
      dictInfoDlgVisible: false,
      dictValueDlgVisible: false,
      dictTypeList: [],
      editInputTable: { single: false },
      dictData: {
      }
      ,dictValueData: {
      },
      currentDict: null,

    };
  },
  computed: {},
  created: function() {
  },
  methods: {
    loadDictValueList: function(dict) {
      this.currentDict = dict;
    },
  }
};
</script>
